package fr.umlv.m2.jee.pmlv.persistence.ldapLink.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import fr.umlv.m2.jee.pmlv.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.pmlv.persistence.ldapLink.UserSubject;
import fr.umlv.m2.jee.pmlv.persistence.ldapLink.UserSubjectPK;

@Repository("hibernateUserSubjectDAO")
public class HibernateUserSubjectDao 
				extends AbstractHibernateDAO<UserSubjectPK, UserSubject >  
				implements IUserSubjectDAO {

    @Override
    public List<UserSubject> findByUserUidAndByYear(String uid, int year) {
            String query = "from UserSubject as us where us.primaryKey.uid = '"+uid+"' and us.primaryKey.year="+year;
            return findByQuery(query);
    }

    @Override
    public List<UserSubject> findByUserUid(String uid) {
            String query = "from UserSubject as us where us.primaryKey.uid = '"+uid+"'";
            return findByQuery(query);
    }

    @Override
    public List<UserSubject> findResponsibleBySubjectAndByYear(long sub_id, int year) {
        String query = "from UserSubject us where us.primaryKey.subject.id="+sub_id+" and us.primaryKey.year="+year+" and us.primaryKey.role='RESPONSIBLE'";
        return findByQuery(query);
    }

}